package com.qwert.shortlink.admin.common.serialize;

import cn.hutool.core.util.DesensitizedUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/7/5 16:19
 **/
public class EmailDesensitizationSerializer extends JsonSerializer<String> {

    /**
     * 邮箱脱敏
     * @param email 脱敏邮箱
     * @param jsonGenerator 对象通用化序列器
     * @param serializerProvider 序列化生产者
     * @throws IOException io异常
     */
    @Override
    public void serialize(String email, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String emailDesensitization = DesensitizedUtil.email(email);
        jsonGenerator.writeString(emailDesensitization);
    }
}
